package com.longge;

import java.util.HashMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class ArrayRankTransform {
    public int[] arrayRankTransform(int[] arr) {

        HashMap<Integer, Integer> map = new HashMap<>();
        int index = 0;
        for (Integer i : IntStream.of(arr).distinct().sorted().boxed().collect(Collectors.toList())) {
            map.put(i, ++index);
        }

        for (int i = 0; i < arr.length; i++) {
            arr[i] = map.get(arr[i]);
        }
        return arr;
    }
}
